import UIManager from "../Managers/UIManager";
import ComponentBase from "../MessageCenter/componentBase";
import Message, {MessageType} from "../MessageCenter/Message";

const {ccclass, property} = cc._decorator;


@ccclass
export default class UIControl extends ComponentBase {

    // 用于展示消息（物品获取消息）
    @property(cc.Node)
    messageNode: cc.Node = null;


    start() {
        // 注册为消息接收者
        let uiManager = new UIManager();
        // TODO UIManager的onload不自动执行，手动调一下
        uiManager.onLoad();
        // UIManager.Instance.onLoad();
        UIManager.Instance.RegisterReceiver(this)
    }

    ReceiveMessage(message: Message) {
        super.ReceiveMessage(message);
        console.log(`UI收到消息`)
        if(message.Command == MessageType.UI_CHANGE_PACKAGE){
            // 得到参数
            this.logMessage(message.Content)
        }
    }

    // 打印消息
    logMessage(item) {
        item.node.destroy();
        this.messageNode.active = true;
    }
}